//ajax请求基尼系数的数据
function getGiNiIndexData(){
  return $.ajax({
    async:false,
    url:"/welcome/GiNiInfo.json",
    type:"GET",
    data:{
      sqlQuery:"SELECT * FROM giniinfo"
    },
    success:function(result,status,xhr){
      return result;
    }
  });
}

//初始化左边的图表
function initGiNiIndexChart(dataCenter,dataSD){
  let myChart=echarts.init(document.getElementById('giNiChart'));
    var dateList = dataCenter.map(function (item) {
        return item[0];
    });
    var valueList = dataSD.map(function (item) {
        return item[1];
    });

    let option = {

        // Make gradient line here
        visualMap: [{
            show: false,
            type: 'continuous',
            seriesIndex: 0,
            min: 0,
            max: 400
        }, {
            show: false,
            type: 'continuous',
            seriesIndex: 1,
            dimension: 0,
            min: 0,
            max: dateList.length - 1
        }],


        title: [{
            left: 'center',
            text: '2007~2018年-中原城市群基尼系数曲线'
        }, {
            top: '55%',
            left: 'center',
            text: '2007~2018年-山东半岛城市群基尼系数曲线'
        }],
        tooltip: {
            trigger: 'axis'
        },
        xAxis: [{
            data: dateList
        }, {
            data: dateList,
            gridIndex: 1
        }],
        yAxis: [{
            min:0,
            max:1,
            splitLine: {show: false}
        }, {
            min:0,
            max:1,
            splitLine: {show: false},
            gridIndex: 1
        }],
        grid: [{
            bottom: '60%'
        }, {
            top: '60%'
        }],
        series: [{
            type: 'line',
            showSymbol: false,
            data: valueList
        }, {
            type: 'line',
            showSymbol: false,
            data: valueList,
            xAxisIndex: 1,
            yAxisIndex: 1
        }]
    };
    myChart.setOption(option);
}




//初始化所有图表
function initWelChart(){
  //1-初始化左边的表
  //基尼系数查询结果
  let giniResult = getGiNiIndexData().responseJSON;
  //遍历json对象的属性，取出属性值
  let cRes=[],sdRes=[];
  //获取中原城市群的值
  let centerGINIObj=giniResult[0];
  for(x in centerGINIObj){
    cRes.push([
      x.substring(1,x.length),centerGINIObj[x]
    ]);
  }
  cRes.shift();
  //获取山东搬到城市群的值
  let sdGINIObj=giniResult[1];
  for(x in sdGINIObj){
    sdRes.push([
      x.substring(1,x.length),sdGINIObj[x]
    ]);
  }
  sdRes.shift();
  //将参数传递给图表：中原城市群，山东半岛城市群
  initGiNiIndexChart(cRes,sdRes);
}


